<?php

class Application_Plugin_Auth extends Zend_Controller_Plugin_Abstract  {
	public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request) {
	//echo md5('admin:Entry your API login and password:1');exit;
           
  			$path = APPLICATION_PATH . '\configs\hello.txt';
            $resolver = new Zend_Auth_Adapter_Http_Resolver_File($path);
            $config = array(
                'accept_schemes' => 'digest',
                'realm'          => 'Entry your API login and password',
                'nonce_timeout'  => 3600,
            	'digest_domains' => '/service'
            
            );
			 $adapter = new Zend_Auth_Adapter_Http($config);

            $adapter->setDigestResolver($resolver);

            $request = $this->getRequest();
            $response = $this->getResponse();

            assert($request instanceof Zend_Controller_Request_Http);
            assert($response instanceof Zend_Controller_Response_Http);

            $adapter->setRequest($request);
            $adapter->setResponse($response);

            $result = $adapter->authenticate();
            if (!$result->isValid()) {
                $response->sendResponse();
            } 
    }

}